package cc.atliberty.structural.composite.ex2;

import java.util.ArrayList;
import java.util.Random;

/**
 * @Author 元宵
 * @url www.atliberty.cc
 * @Date 2023-10-31 08:51
 * @description:
 */
public class Client {
    public static void main(String[] args) {
        ArrayList<Component> list = new ArrayList<>();
        String[] strs = {"Composite","Leaf"};
        Random random = new Random();
        String str = null;
        int r = 0;
        for (int i = 0; i < 10; i++) {
            r = random.nextInt(2);
            System.out.println(i + "---" + strs[r]);
            try {
                Component component = (Component) Class.forName(Client.class.getPackageName() + "." + strs[r]).newInstance();
                component.sampleOperation();
            } catch (Exception e) {
                e.printStackTrace();
            } 
            for (Component component : list) {
                component.sampleOperation();
            }
        }
    }
}
